package sing.myapp

import android.content.pm.PackageManager
import sing.core.Global
import sing.core.base.BaseApp
import sing.core.util.MMkvUtil
import sing.myapp.router.RouterConfig

class MyApp : BaseApp() {

    override fun onCreate() {
        super.onCreate()

        RouterConfig.init(this)
        Global.channel = getChannel()
    }

    private fun getChannel(): String {
        var channel = ""
        val key = "UMENG_CHANNEL"
        try {
            val packageManager = packageManager
            if (packageManager != null) {
                val applicationInfo = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
                if (applicationInfo != null) {
                    if (applicationInfo.metaData != null) {
                        channel = "${applicationInfo.metaData?.getString(key)}"
                    }
                }
            }
        } catch (e: PackageManager.NameNotFoundException) {
            e.printStackTrace()
        }
        return channel
    }
}